package com.wxblockchain.core.config;

import com.wxblockchain.core.R;
import com.wxblockchain.core.manager.KVCacheManager;
import com.wxblockchain.core.manager.ToastManager;

/**
 * Created by louyaming on 2020/04/24
 */
public class UrlConfig {
    interface Environment {
        int PRD = 0;
        int DEV = 1;
    }

    private static final String Environment_Config_Key = "core_url_config_key";
    /**
     * 第三方接入:模式选择： PRD生产模式，STG测试模式,
     */
    private static int MODEL = Environment.PRD;

    /**
     * 根据保存的信息初始化api环境
     */
    public static void initApiEnvironment() {
        MODEL = KVCacheManager.getInstance().getInt(Environment_Config_Key, Environment.PRD);
        refreshApi();
    }

    /**
     * 切换测试环境和生产环境
     *
     * @param model
     */
    public static void changeApiEnvironment(int model) {
        if (model != Environment.DEV && model != Environment.PRD) {
            ToastManager.showToast(R.string.core_params_error);
            return;
        }
        MODEL = model;
        refreshApi();

        KVCacheManager.getInstance().saveInt(Environment_Config_Key,MODEL);
    }

    /**
     * 根据环境设置,初始化各url
     */
    private static void refreshApi() {
        if (MODEL == Environment.DEV) {
            URL_ROOT = URL_ROOT_DEV;
        } else {
            URL_ROOT = URL_ROOT_PRD;
        }
    }

    /*=============================== 接口服务器 ================================*/
    public static String URL_ROOT_PRD = "https://ehs.pingan.com.cn";
    public static String URL_ROOT_DEV = "https://test-mhis-siapp.pingan.com.cn:57443";
    public static String URL_ROOT = URL_ROOT_PRD;
    /*================================ end ====================================*/
}